def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True

def largest_prime_from_digits(number):
    if len(str(number)) != 4:
        return 0

    digits = [int(d) for d in str(number)]
    largest_prime = 0

    for i in range(4):
        for j in range(i, 4):
            if i == j:
                continue
            num = int(str(digits[i]) + str(digits[j]))
            if is_prime(num) and num > largest_prime:
                largest_prime = num
    
    return largest_prime

input_number = int(input("Введите четырёхзначное натуральное число: "))
result = largest_prime_from_digits(input_number)
print(result)
